/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ie.tcd.cs.railtickets.server.demo;

import ie.tcd.cs.railtickets.server.dao.AgentDAO;
import static ie.tcd.cs.railtickets.commons.util.DateUtil.createDate;
import ie.tcd.cs.railtickets.server.dao.DAOFactory;
import ie.tcd.cs.railtickets.server.dao.PathTimeDAO;
import ie.tcd.cs.railtickets.server.dao.RouteDAO;
import ie.tcd.cs.railtickets.server.dao.RouteStationDAO;
import ie.tcd.cs.railtickets.server.dao.RouteTimeDAO;
import ie.tcd.cs.railtickets.server.dao.StationDAO;
import ie.tcd.cs.railtickets.server.dao.TravelPathDAO;
import ie.tcd.cs.railtickets.server.domain.Agent;
import ie.tcd.cs.railtickets.server.domain.PathTime;
import ie.tcd.cs.railtickets.server.domain.Route;
import ie.tcd.cs.railtickets.server.domain.RouteStation;
import ie.tcd.cs.railtickets.server.domain.RouteTime;
import ie.tcd.cs.railtickets.server.domain.Station;
import ie.tcd.cs.railtickets.server.domain.TravelPath;
import java.text.ParseException;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Wenbo Sun
 */
public class InitDB1 {

    public InitDB1() {
    }

    public void excute() {
        this.initStations();
        this.initRoutes();
        this.initRouteStations();
        this.initTravelPaths();
        this.initRouteTimes();
        this.initPathTimes();
        initAgents();
    }

    public void initStations() {
        StationDAO dao = DAOFactory.createStationDAO();
        dao.save(new Station("a"));
        dao.save(new Station("b"));
        dao.save(new Station("c"));
        dao.save(new Station("d"));
        dao.save(new Station("e"));
        dao.save(new Station("f"));
        dao.save(new Station("g"));
        dao.save(new Station("h"));
        dao.save(new Station("i"));
        dao.save(new Station("j"));
        dao.save(new Station("k"));
        dao.save(new Station("l"));
        dao.save(new Station("m"));
    }

    public void initRoutes() {
        RouteDAO dao = DAOFactory.createRouteDAO();
        dao.save(new Route("r1", "rn1", 145));
        dao.save(new Route("r2", "rn2", 165));
        dao.save(new Route("r3", "rn3", 136));
        dao.save(new Route("r4", "rn4", 144));
        dao.save(new Route("r5", "rn5", 178));
        dao.save(new Route("r6", "rn6", 133));
        dao.save(new Route("r7", "rn7", 152));
    }

    public void initRouteStations() {
        RouteStationDAO dao = DAOFactory.createRouteStationDAO();
        dao.save(new RouteStation(new Route(1), new Station(1), 1));
        dao.save(new RouteStation(new Route(1), new Station(2), 2));
        dao.save(new RouteStation(new Route(1), new Station(3), 3));
        dao.save(new RouteStation(new Route(1), new Station(4), 4));
        dao.save(new RouteStation(new Route(1), new Station(5), 5));
        dao.save(new RouteStation(new Route(3), new Station(5), 1));
        dao.save(new RouteStation(new Route(3), new Station(4), 2));
        dao.save(new RouteStation(new Route(3), new Station(3), 3));
        dao.save(new RouteStation(new Route(3), new Station(2), 4));
        dao.save(new RouteStation(new Route(3), new Station(1), 5));
        dao.save(new RouteStation(new Route(2), new Station(3), 1));
        dao.save(new RouteStation(new Route(2), new Station(2), 2));
        dao.save(new RouteStation(new Route(2), new Station(6), 3));
        dao.save(new RouteStation(new Route(2), new Station(8), 4));
        dao.save(new RouteStation(new Route(4), new Station(9), 1));
        dao.save(new RouteStation(new Route(4), new Station(4), 2));
        dao.save(new RouteStation(new Route(4), new Station(8), 3));
        dao.save(new RouteStation(new Route(4), new Station(6), 4));
        dao.save(new RouteStation(new Route(4), new Station(10), 5));
    }

    public void initTravelPaths() {
        TravelPathDAO dao = DAOFactory.createTravelPathDAO();
        dao.save(new TravelPath(new RouteStation(1), new RouteStation(2), 10));
        dao.save(new TravelPath(new RouteStation(1), new RouteStation(3), 40));
        dao.save(new TravelPath(new RouteStation(2), new RouteStation(3), 35));
        dao.save(new TravelPath(new RouteStation(3), new RouteStation(4), 15));
        dao.save(new TravelPath(new RouteStation(1), new RouteStation(4), 52));
        dao.save(new TravelPath(new RouteStation(2), new RouteStation(4), 45));
        dao.save(new TravelPath(new RouteStation(4), new RouteStation(5), 20));
        dao.save(new TravelPath(new RouteStation(1), new RouteStation(5), 70));
    }

    public void initRouteTimes() {
        try {
            RouteTimeDAO dao = DAOFactory.createRouteTimeDAO();
            dao.save(new RouteTime(createDate("13:00", "hh:mm"), 10.5, new Route(1)));
            dao.save(new RouteTime(createDate("23:00", "hh:mm"), 10.5, new Route(1)));
            dao.save(new RouteTime(createDate("08:00", "hh:mm"), 7, new Route(2)));
            dao.save(new RouteTime(createDate("15:00", "hh:mm"), 7, new Route(2)));
            dao.save(new RouteTime(createDate("22:00", "hh:mm"), 7, new Route(2)));
        } catch (ParseException ex) {
            Logger.getLogger(InitDB1.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    public void initPathTimes() {
        try {
            PathTimeDAO dao = DAOFactory.createPathTimeDAO();
            dao.save(new PathTime(createDate("13:00", "hh:mm"), 1.2, new TravelPath(1), new RouteTime(1)));
            dao.save(new PathTime(createDate("13:00", "hh:mm"), 3.5, new TravelPath(2), new RouteTime(1)));
            dao.save(new PathTime(createDate("14:30", "hh:mm"), 2.7, new TravelPath(3), new RouteTime(1)));
            dao.save(new PathTime(createDate("17:30", "hh:mm"), 1.5, new TravelPath(4), new RouteTime(1)));
        } catch (ParseException ex) {
            Logger.getLogger(InitDB1.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void initAgents() {
        AgentDAO dao = DAOFactory.createAgentDAO();
        dao.save(new Agent("0.0.0.0", "talent rail", Calendar.getInstance().getTime()));

    }
}
